/*
 * This file is part of the Boring Engine.
 *
 * Copyright (c) 2011 by pf5234 <pf5234@users.sourceforge.net>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

package com.googlecode.boringengine;

import com.googlecode.boringengine.internal.Engine;
import java.util.Calendar;
import java.util.TimeZone;

public class Util {

    public static String getDateTime() {
        Calendar a = Calendar.getInstance(TimeZone.getDefault());
        int month = a.get(Calendar.MONTH) + 1;
        int day = a.get(Calendar.DAY_OF_MONTH);
        int year = a.get(Calendar.YEAR);
        int hour = a.get(Calendar.HOUR_OF_DAY);
        int minute = a.get(Calendar.MINUTE);
        int second = a.get(Calendar.SECOND);
        String time = String.format("%02d%02d%02d%02d%02d%02d", year, month, day, hour, minute, second);
        return time;
    }

    public static String stringifyException(Exception ex) {
        Throwable e = ex;
        String stackTrace = e.toString();
        StackTraceElement[] stack = e.getStackTrace();
        for (StackTraceElement s : stack)
            stackTrace += "\n - " + s.toString();
        while (e.getCause() != null) {
            e = e.getCause();
            stackTrace += "\nCaused by " + e;
            stack = e.getStackTrace();
            for (StackTraceElement s : stack)
                stackTrace += "\n - " + s.toString();
        }
        return stackTrace;
    }

    public static void addMenu(Menu<?> m) {
        Engine.addMenu(m);
    }

    private Util() {
    }
}
